package com.lt.lumentracks.controller;


import com.lt.lumentracks.context.BaseContext;
import com.lt.lumentracks.entity.vo.common.Result;
import com.lt.lumentracks.entity.vo.user.UserVO_conversationList;
import com.lt.lumentracks.service.IUserBlacklistService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 黑名单表，记录用户之间的拉黑情况 前端控制器
 * </p>
 *
 * @author swl
 * @since 2025-10-24
 */
@RestController
@RequestMapping("/user-blacklist")
public class UserBlacklistController {

    @Autowired
    private IUserBlacklistService iUserBlacklistService;

    // 拉黑
    @PostMapping("/{targetId}")
    public Result<String> block(@PathVariable Integer targetId) {
        Integer userId = BaseContext.getCurrentId();
        return iUserBlacklistService.block(userId, targetId);
    }

    // 解除拉黑
    @DeleteMapping("/{targetId}")
    public Result<String> unblock(@PathVariable Integer targetId) {
        Integer userId = BaseContext.getCurrentId();
        return iUserBlacklistService.unblock(userId, targetId);
    }

    // 获取被拉黑的用户列表
    @GetMapping("/list")
    public Result<List<UserVO_conversationList>> blockedList() {
        Integer userId = BaseContext.getCurrentId();
        return Result.success(iUserBlacklistService.getBlockedList(userId));
    }

    // 查询是否拉黑了某用户
    @GetMapping("/isBlocked/{targetId}")
    public Result<Boolean> isBlocked(@PathVariable Integer targetId) {
        Integer userId = BaseContext.getCurrentId();
        Boolean res = iUserBlacklistService.isBlocked(userId, targetId);
        return res ? Result.success(true) : Result.success(false);
    }

}
